package yxy.game.pm2.command.shop;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ShopMessage;
import yxy.game.pm2.module.shop.handle.HeroConvertHandle;

/** 商店 神将兑换 */
@MessageType(proto = Command.HeroConvert, classtype = ShopMessage.HeroConvertRequest.class)
public class CMD_HeroConvert extends Command<ShopMessage.HeroConvertRequest> {

	@Override
	public void execute(MessageSource messageSource, ShopMessage.HeroConvertRequest request) {
		String playerCode = messageSource.getTag();

		ShopMessage.HeroConvertResponse.Builder response = ShopMessage.HeroConvertResponse.newBuilder();

		response.addAllGoods(new HeroConvertHandle().goods(playerCode));

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ShopMessage.HeroConvertResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}